#ifndef __PROJECTION_SCREEN_H__
#define __PROJECTION_SCREEN_H__

#include "include.h"
#include "user_include.h"
// #include "k_pid.h"
#include "lv_filter.h"

#define FLASH_POS_ADDR      0

#define ADC_ANGLE_MAX       3800    //电位器最大分压有效数值    ADC_ANGLE_MAX/360 角度分辨率
#define ANGLE_STEP          (u8)(ADC_ANGLE_MAX/360)

#define PS_ZERO_CIRCLE      1000
#define RESET_PWM           100    
#define RUNNING_PWM         150

#define STOP_END_CUR        500

#define PS_END_STOP           1200
#define PS_START_STOP         1000

enum E_PS_dir {e_PS_open, e_PS_close};
enum E_PS_sta {PS_STANDBY, PS_RUN, PS_STOP, PS_RESET, PS_ERR};
enum E_PS_err {ERR_OVERCUR, ERR_ONANGLE, ERR_VOERVOLT, ERR_LOWVOLT, ERR_STALL};
   
#define PS_SET_OPEN_PWM(x)      SET_PWM_ch0_1(x)
#define PS_SET_CLOSE_PWM(x)     SET_PWM_ch2_3(x)

#define RF_CMD_OPEN         16  
#define RF_CMD_CLOSE        8  
#define RF_CMD_STOP         4  
#define RF_CMD_RESET        2  

#define CUR_OVERLOAD        3000

typedef struct{
    u16 circle; //圈数
    u16 angle;  //角度 0-4096 细分360
}PS_def_position;

extern u8 PS_sta;
extern u8 PS_sta_new;
extern u8 PS_dir;
extern u8 PS_err;
extern u16 PS_pwm;
extern u16 PS_current;

extern PS_def_position PS_postion;
extern PS_def_position PS_tar_postion;

extern _lv_filter PS_angle;
extern _lv_filter PS_cur;

void P_screen_init(void);

void P_screen_crt_loop(void);
void P_screen_sta_loop(void);
void P_screen_reset_loop(void);
void P_screen_RF433_loop(void);

void P_sceen_angle_convert(u16 value);
void P_screen_current_convert(u16 value);

void P_screen_set_move(u8 dir, u16 target);
void P_screen_set_stop(void);
void P_screen_set_reset(void);
void P_screen_set_err(void);

#endif
